package com.lcz.manage.sys.service.consumer.factory;


import com.lcz.manage.sys.service.consumer.IConsumer;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class ConsumerFactory {

    public enum ConsumerType{
        /** MQ */
        MQ,
        /** REDIS */
        REDIS
    }

    private static final Map<ConsumerType, IConsumer> CONSUMER_MAP = new ConcurrentHashMap<>();

    public synchronized void register(ConsumerType consumerType, IConsumer iConsumer) {
        CONSUMER_MAP.putIfAbsent(consumerType, iConsumer);
    }

    public IConsumer get(ConsumerType consumerType) {
        return CONSUMER_MAP.getOrDefault(consumerType, null);
    }

}
